#!/usr/bin/env bash
################################################################################
# wimi - check the WhatIsMyIP.com site results                                 #
#                                                                              #
# @author    David Christian Liedle <david.liedle@gmail.com>                   #
# @copyright Copyright (c) 2009-2011 David Christian Liedle                    #
# @license   MIT Open Source License / CC-BY 3.0                               #
#             http://www.opensource.org/licenses/mit-license.php               #
#              http://creativecommons.org/licenses/by/3.0/                     #
#                                                                              #
#  Released as part of The CLIMAX/Candy Suite: http://climax.googlecode.com/   #
#                                                                              #
# Credit / Thanks:                                                             #
# "WIMI" (the website) IP checking service provided by:                        #
#  WhatIsMyIP.com (many thanks for the dedicated lookup page!)                 #
#                                                                              #
################################################################################

WIMI_CHECKSITE="http://www.whatismyip.com/automation/n09230945.asp"


################################################################################
# Control/Output:
#

if [ $1 ]; then

   if [ $1 == "-h" ]; then
      echo "wimi - check your public IP address from the CLI"
      echo "Flags:"
      echo " -h       Help (this flag has been triggered)"
      echo " -l	      Log (NOT YET IMPLEMENTED)"
      echo " -s	      Silent (just IP, thanks!)"
      echo " -v	      Verbose (Shows whats going on)"
      exit 0
   fi

   if [ $1 == "-l" ]; then
      echo "[`date`] `curl -s $WIMI_CHECKSITE`" >> ~/.wimi
      echo -n "Public IP Log: "
      tail -n 1 ~/.wimi
      exit 0
   fi

   if [ $1 == "-s" ]; then
      curl $WIMI_CHECKSITE
      echo
      exit 0
   fi

   if [ $1 == "-v" ]; then
      echo "Checking public IP from: $WIMI_CHECKSITE"
      echo -n "Readout: "
      curl $WIMI_CHECKSITE
      echo
      exit 0
   fi

   echo "Uncaught flag..."
   exit 1

else
    echo -n "My IP is: "
    curl $WIMI_CHECKSITE
    echo
    exit 0
fi



################################################################################
# ...and we're done! ;]
#

exit 0
